﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Core;

namespace Yuanlin.Business
{
    public class CompanyRecommendedProducts : YuanlinUserControl,
        IReplyConverter<CompanyProductReply, GetListOperation>
    {
        protected Repeater list;
        private EntityList companyProducts;

        public override void GetRequests(List<BaseRequestBinder> requestBinders)
        {
            CompanyProductListRequest request = new CompanyProductListRequest();
            request.UserId = UserIdFromGreenNum;
            request.PageIndex = 0;
            request.PageSize = Count;
            requestBinders.Add(RequestHelper.BuildGetCompanyProductListRequest(this, request));
        }

        public virtual int Count
        {
            get
            {
                Object state = ViewState["Count"];
                if (state != null)
                {
                    return (int)state;
                }
                return 6;
            }
            set
            {
                ViewState["Count"] = value;
            }
        }

        private void BindData()
        {
            list.DataSource = companyProducts;
            list.DataBind();
        }

        #region IReplyConverter<CompanyProductReply,GetListOperation> Members

        public void ConvertReply(CompanyProductReply reply, GetListOperation operation)
        {
            if (reply != null)
            {
                companyProducts = reply.EntityList;

                if (!IsPostBack)
                {
                    BindData();
                }
            }
        }

        #endregion
    }
}
